﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="frmListsGuestsOld.ascx.cs" Inherits="GUESTSMANAGEMENT.View.ListsGuests.frmListsGuests" %>
<%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>
<%@ Register Src="~/View/ListsGuests/frmInvite.ascx" TagName="GuestInvite" TagPrefix="GMInvite"%>

<ext:ScriptManagerProxy ID="ScriptManagerProxy" runat="server">
</ext:ScriptManagerProxy>

<script type="text/javascript">
    var openWindowListsGuests = function() {
    var winGrdListsGuests = <%= winGrdListsGuests.ClientID %>;
        winGrdListsGuests.show();
    }

    var getListsGuestsId = function(grid, rowIndex, columnIndex, e) {
        var t = e.getTarget();
        var record = grid.getStore().getAt(rowIndex);
        var columnId = grid.getColumnModel().getColumnId(columnIndex);
        var columnValue = grid.getColumnModel().getDataIndex(3);
        var id = record.get(columnValue);
        <%=txt_idGuest.ClientID %>.setValue(id);
    }
    
    var getListGuestInvite = function(grid, rowIndex, columnIndex, e){
        var t = e.getTarget();
        var record = grid.getStore().getAt(rowIndex);
        var columnId = grid.getColumnModel().getColumnId(columnIndex);
        var columnValue = grid.getColumnModel().getDataIndex(2);
        var invite = record.get(columnValue);
        <%=txt_idInvite.ClientID %>.setValue(invite);
    }
        
</script>

<ext:TokenScript runat="server">
    <script type="text/javascript">
        var applyFilter = function () {
            #{guestsStore}.filterBy(getRecordFilter());
        }
        
        var clearFilter = function () {
            #{guestsNameFilter}.reset();
            #{guestsMailFilter}.reset();
            
            #{guestsStore}.clearFilter();
        }

        var filterString = function (value, dataIndex, record) {
            var val = record.get(dataIndex);
            if (typeof val != "string") {
                return value.length == 0;
            }
            return val.toLowerCase().indexOf(value.toLowerCase()) > -1;
        }

        var getRecordFilter = function () {
            var f = [];

            f.push({
                filter: function(record) {                         
                    return filterString(#{guestsNameFilter}.getValue(), 'NMGUEST', record);
                }
            });
            
            f.push({
                filter: function(record) {                         
                    return filterString(#{guestsMailFilter}.getValue(), 'NMMAIL', record);
                }
            });
            
            var len = f.length;
            return function(record) {
                for (var i = 0; i < len; i++) {
                    if (!f[i].filter(record)) {
                        return false;
                    }
                }
                return true;
            };
        }  
    </script>
</ext:TokenScript>


<ext:DesktopWindow ID="winGrdListsGuests" runat="server" Collapsible="true" Icon="Group" Title="Convidados" Width="588" Height="400">
    <Body>
        <ext:Hidden ID="txt_idGuest" runat="server"></ext:Hidden>
        <ext:Hidden ID="txt_idCdEvent" runat="server"></ext:Hidden>
        <ext:Hidden ID="txt_idCdUser" runat="server"></ext:Hidden>
        <ext:Hidden ID="txt_idInvite" runat="server"></ext:Hidden>
        <ext:Store ID="guestsStore" runat="server" OnRefreshData="Refresh" RefreshAfterSaving="Auto">
            <Reader>
                <ext:JsonReader>
                    <Fields>
                        <ext:RecordField Name="CDGUEST" />
                        <ext:RecordField Name="NMGUEST" />
                        <ext:RecordField Name="NMMAIL" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store> 
        <ext:FitLayout ID="FitLayout1" runat="server">
            <ext:GridPanel ID="listsGuestsGridPanel" 
                runat="server"
                StoreID="guestsStore"
                StripeRows="true"
                Width="450" 
                Height="290"
                AutoExpandColumn="guestsName">
                <TopBar>
                    <ext:Toolbar ID="ToolBar1" runat="server">
                        <Items>
                            <ext:ToolbarButton ID="btnSaveListsGuests" Icon="Disk" runat="server">
                                <ToolTips>
                                    <ext:ToolTip ID="ToolTip" runat="server" Title="Salvar Convidado">
                                    </ext:ToolTip>
                                </ToolTips>
                                <AjaxEvents>
                                    <Click OnEvent="SaveListsGuest"> 
                                    </Click>
                                </AjaxEvents>
                                
                            </ext:ToolbarButton>
                            <ext:ToolbarSeparator ID="ToolbarSeparator" runat="server">
                            </ext:ToolbarSeparator>
                            <ext:ToolbarButton ID="btnCloseListsGuests" runat="server" Icon="DoorIn">
                                <Listeners>
                                    <Click Handler="#{winGrdListsGuests}.hide(null);" />
                                </Listeners>
                                <AjaxEvents>
                                    <Click OnEvent="Close"></Click>
                                </AjaxEvents>
                                <ToolTips>
                                    <ext:ToolTip ID="CloseNewListsGuests" runat="server" Title="Sair"></ext:ToolTip>
                                </ToolTips>
                            </ext:ToolbarButton>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:Column ColumnID="guestsName" Header="Nome" Width="170" DataIndex="NMGUEST" Sortable="true" />
                        <ext:Column ColumnID="guestsEmail" Header="E-mail" Width="270" DataIndex="NMMAIL" Sortable="true" />
                        <ext:Column ColumnID="guestsInvite" DataIndex="TESTE" />
                        <ext:Column ColumnID="guestsCDGUESTS" Hidden="true" DataIndex="CDGUEST"/>
                    </Columns>
                </ColumnModel>
                <Listeners>
                    <CellClick Fn="getListsGuestsId" />
                </Listeners>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionMode" runat="server">
                        <Listeners>
                            <RowSelect  Handler="#{btnCloseListsGuests}.enable();" />
                        </Listeners>                       
                    </ext:RowSelectionModel>
                </SelectionModel>
                <View>
                    <ext:GridView ID="GridView1" runat="server">
                        <HeaderRows>
                            <ext:HeaderRow>
                                <Columns>                                    
                                    <ext:HeaderColumn Cls="x-small-editor">
                                        <Component>
                                            <ext:TextField ID="guestsNameFilter" runat="server" EnableKeyEvents="true">
                                                <Listeners>
                                                    <KeyUp Handler="applyFilter();" Buffer="250" />                                                
                                                </Listeners>
                                            </ext:TextField>
                                        </Component>
                                    </ext:HeaderColumn>
                                    <ext:HeaderColumn Cls="x-small-editor">
                                        <Component>
                                            <ext:TextField ID="guestsMailFilter" runat="server"  EnableKeyEvents="true">
                                                <Listeners>
                                                    <KeyUp Handler="applyFilter();" Buffer="250" />
                                                </Listeners>
                                            </ext:TextField>
                                        </Component>
                                    </ext:HeaderColumn>
                                    <ext:HeaderColumn AutoWidthElement="false">
                                        <Component>
                                            <ext:Button ID="ClearFilterButton" runat="server" Icon="Cross">
                                                <ToolTips>
                                                    <ext:ToolTip ID="ToolTip1" runat="server" Html="Limpar Filtros" />
                                                </ToolTips>
                                                <Listeners>
                                                    <Click Handler="clearFilter();" />
                                                </Listeners>                                            
                                            </ext:Button>
                                        </Component>
                                    </ext:HeaderColumn>
                                </Columns>
                            </ext:HeaderRow>
                        </HeaderRows>
                    </ext:GridView>
                </View>
                <LoadMask ShowMask="true" />
                <SaveMask ShowMask="true" />
                <BottomBar>
                    <ext:PagingToolBar ID="PagingToolBar" runat="server" PageSize="50" StoreID="guestsStore" />
                </BottomBar>
            </ext:GridPanel>
        </ext:FitLayout>
        <GMInvite:GuestInvite ID="GMInvite" runat="server" />
    </Body>
    <BottomBar>
        <ext:StatusBar ID="FormStatusBar" runat="server" DefaultText="Ready">
            <Plugins>
                <ext:ValidationStatus ID="ValidationStatus1" runat="server" FormPanelID="StatusForm" ValidIcon="Accept" ErrorIcon="Exclamation" />
            </Plugins>
        </ext:StatusBar>
    </BottomBar>
</ext:DesktopWindow>
